<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 方法一 暴力法 超时
        var maxArea = function (height) {
            let len = height.length;
            let area = 0;
            for (let i = 0; i < len - 1; i++) {
                for (let j = i + 1; j < len; j++) {
                    if (height[i] >= height[j]) {
                        let a1 = (j - i) * height[j];
                        if (area < a1) {
                            let temp = area;
                            area = a1;
                            a1 = temp;
                        }
                    } else {
                        let a1 = (j - i) * height[i];
                        if (area < a1) {
                            let temp = area;
                            area = a1;
                            a1 = temp;
                        }
                    }
                }
            }
            return area;
        };
        // 方法二 双指针
        var maxArea = function (height) {
            let len = height.length;
            let area = 0;
            for (let left = 0, right = len - 1; left < right;) {
                let a1 = Math.min(height[left], height[right]) * (right - left);
                area = Math.max(area, a1);
                if (height[left] > height[right]) {
                    right--;
                } else {
                    left++;
                }
            }
            return area;
        };
        console.log(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]));
    </script>
</head>

<body>

</body>

</html>